import { _get, _post } from "../../utils/request";
import util from "../../utils/util";
import { debounce, throttle } from "../../utils/debounce";
const app = getApp();

Page({
    data: {
        animationInfo: {},

        //轮播图
        background: [
            "../../images/traffic.jpg",
            "../../images/security.jpg",
            "../../images/computer.jpg",
        ],
        indicatorDots: true,
        autoplay: true,
        vertical: false,
        interval: 2000,
        circular: false,

        confirm: [],
        test: [],
        review: [],
        floorstatus: false,
    },
    //使用节流防抖须使用function而不是箭头函数，因为this指向不同
    test11: throttle(function(e) {
        console.log(this);
    }, 2000),
    // 获取滚动条当前位置

    onPageScroll(e) {
        // console.log(e)
        if (e.scrollTop > 100) {
            this.setData({
                floorstatus: true,
            });
        } else {
            this.setData({
                floorstatus: false,
            });
        }
    },

    //回到顶部
    goTop(e) {
        // 一键回到顶部
        if (dd.pageScrollTo) {
            dd.pageScrollTo({
                scrollTop: 0,
            });
        } else {
            dd.alert("版本过低不支持");
        }
    },

    jump_test() {
        dd.navigateTo({
            url: "/pages/mytest/test/test",
        });
    },
    jump_result() {
        dd.navigateTo({
            url: "/pages/result/result",
        });
    },
    jump_equip() {
        dd.navigateTo({
            url: "/pages/equip/equip",
        });
    },
    jump_standard() {
        dd.navigateTo({
            url: "/pages/standard/standard",
        });
    },
    jump_set() {
        dd.navigateTo({
            url: "/pages/set/set",
        });
    },
    jump_confirm(e) {
        console.log("e", e);

        app.confirmId = e.currentTarget.id;
        dd.navigateTo({
            url: "/pages/confirm/confirm",
        });
    },
    jump_test_confirm(e) {
        // console.log("e", e);
        app.vbizId = e.currentTarget.id;
        app.confirmId = e.currentTarget.id;
        app.test_id = e.currentTarget.id;
        dd.navigateTo({
            url: "/pages/mytest/test_confirm/test_confirm",
        });
    },
    jump_review(e) {
        app.review_id = e.currentTarget.id;
        dd.navigateTo({
            url: "/pages/review/review",
        });
    },
    //获取确认工单列表
    getConfirm() {
        let params = {
            userId: app.userId,
            workerName: "",
        };
        _get(`/vbizMain/selectWait`, params).then((res) => {
            // console.log(res);
            console.log("confirm", res.data);
            this.setData({
                confirm: res.data,
            });
        });
    },
    //获取待待测工单列表
    getTest() {
        let params = {
            userId: app.userId,
            workerName: "",
        };
        _get(`/vbizMain/selectTest`, params).then((res) => {
            // console.log(res);
            // console.log('test', res.data);
            this.setData({
                test: res.data,
            });
        });
    },
    //获取待校核工单列表
    getReview() {
        let params = {
            userId: app.userId,
            workerName: "",
        };
        _get(`/vbizMain/selectRecheck`, params).then((res) => {
            // console.log(res);
            // console.log('review', res.data);
            this.setData({
                review: res.data,
            });
        });
    },

    // 直接调接口是可以的， 应该就是request.js里没封装好
    // requestInfo() {
    //     dd.httpRequest({
    //         url: 'http://192.168.1.102:8082/work/waitConfirm',
    //         method: 'GET',
    //         data: { userId: 3 },
    //         // dataType: 'json',
    //         success: function(res) {
    //             // dd.alert({ content: 'success' + res.data.id });
    //               console.log(1);
    //             console.log(this.data.confirm);
    //             console.log('confirm', res.data.data);

    //             this.setData({
    //                 confirm: res.data.data
    //             })

    //         },
    //         fail: function(res) {
    //             // dd.alert({ content: 'fail' });
    //         },
    //         // complete: function(res) {
    //         //     dd.alert({ content: 'complete' });
    //         //     my.hideLoading();
    //         // }
    //     });

    // },
    onShow() {

        this.getConfirm();
        this.getTest();
        this.getReview();
    },
    onLoad() {
        //设置导航栏
        dd.setNavigationBar({
            title: "功能页",
            backgroundColor: "#142e4f",
            success() {},
            fail() {},
        });
        this.getConfirm();
        this.getTest();
        this.getReview();
    },

    onReady() {
        // this.requestInfo()
    },
});